﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class AddZs : System.Web.UI.Page
{
    DataClassesDataContext dc = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        cmbDwxz.DataSource = dc.css_dwxz;
        cmbDwxz.ValueField = "xzbh";
        cmbDwxz.TextField = "xzmc";
        cmbDwxz.DataBind();
        cmbFzjg.DataSource = dc.css_fzjg;
        cmbFzjg.ValueField = "jgbh";
        cmbFzjg.TextField = "jgmc";
        cmbFzjg.DataBind();
        cmbSscq.DataSource = dc.css_cqxx;
        cmbSscq.ValueField = "cqbh";
        cmbSscq.TextField = "cqmc";
        cmbSscq.DataBind();
    }
    void insertZs()
    {
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            css_dwxx dw = new css_dwxx();
            dw.dwmc = txtDwmc.Text.Trim();
            dw.dwxz = cmbDwxz.Value.ToString();
            dw.sscq = cmbSscq.Value.ToString();
            dw.fzr = txtFzr.Text.Trim();
            dw.fzjg = cmbFzjg.Value.ToString();
            dw.fzrq = txtFzrq.Text.Trim();
            dw.fwdz = txtFwdz.Text.Trim();
            dw.zh = txtZh.Text.Trim();
            dc.css_dwxx.InsertOnSubmit(dw);
            dc.SubmitChanges();
            Frame.Global.GlobalFunctions.Alert("证书登记成功");
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (txtDwmc.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("单位名称不允许为空");
        }
        else if (cmbDwxz.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("单位性质不允许为空");
        }
        else if (cmbSscq.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("所属城区不允许为空");
        }
        else if (txtFwdz.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("服务地址不允许为空");
        }
        else if (cmbFzjg.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("发证机关不允许为空");
        }
        else if (txtZh.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("证号不允许为空");
        }
        else if (txtFzr.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("负责人不允许为空");
        }
        else if (txtFzrq.Text == "")
        {
            Frame.Global.GlobalFunctions.Alert("发证日期不允许为空");
        }
        else
        {
            insertZs();
        }
    }
    protected void btnEsc_Click(object sender, EventArgs e)
    {
        txtZh.Text = "";
        txtDwmc.Text = "";
        txtFwdz.Text = "";
        txtFzr.Text = "";
        txtFzrq.Text = "";
        cmbSscq.Text = "";
        cmbFzjg.Text = "";
        cmbDwxz.Text = "";
    }
}